"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Authentication = void 0;
const mes_1 = __importDefault(require("../../utils/mes"));
const jwt_1 = require("../../utils/jwt");
class Authentication {
}
exports.Authentication = Authentication;
_a = Authentication;
Authentication.isLogin = (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
    var _b;
    try {
        const token = (_b = req.headers.authorization) === null || _b === void 0 ? void 0 : _b.slice(7);
        if (!(token === null || token === void 0 ? void 0 : token.trim()))
            throw 'token不存在';
        const result = (0, jwt_1.parseToken)(token);
        if (!result.success)
            throw result.data;
        next();
    }
    catch (error) {
        res.status(401).send(mes_1.default.failed(error));
    }
});
